﻿using System;
using AccessControl.Wpf.ViewModels;
using AccessControl.Contracts.Settings;
using AccessControl.Contracts.Models;

namespace AccessControl.Wpf.Settings.ViewModels
{
	class SettingsViewModel : ActiveItemViewModelManager, IActionViewModel
	{
		#region Public Constructors
		
		public SettingsViewModel(ISettingsService settingsService)
		{
			ViewModels.Add(new EntriesSettingsViewModel(settingsService));
			ViewModels.Add(new UsersSettingsViewModel(settingsService));
			ViewModels.Add(new OperatorsSettingsViewModel(settingsService));
			ViewModels.Add(new SensorsSettingsViewModel(settingsService));
			ViewModels.Add(new CamerasSettingsViewModel(settingsService));
			ViewModels.Add(new MapsSettingsViewModel(settingsService));
		}

		public SettingsViewModel(ISettingsService settingsService, Messaging.IMessagingService MessagingService)
		{
			ViewModels.Add(new EntriesSettingsViewModel(settingsService) { MessagingService = MessagingService });
			ViewModels.Add(new UsersSettingsViewModel(settingsService) { MessagingService = MessagingService });
			ViewModels.Add(new OperatorsSettingsViewModel(settingsService) { MessagingService = MessagingService });
			ViewModels.Add(new SensorsSettingsViewModel(settingsService) { MessagingService = MessagingService });
			ViewModels.Add(new CamerasSettingsViewModel(settingsService) { MessagingService = MessagingService });
			ViewModels.Add(new MapsSettingsViewModel(settingsService) { MessagingService = MessagingService });
		}

		#endregion

		#region Overrides

		protected override void OnActiveItemChanging(ViewModel oldValue, ViewModel newValue)
		{
			if (newValue != null)
				((ISettingsBaseViewModel)newValue).LoadSettings();
		}

		#endregion

		#region IActionViewModel Members

		public Contracts.Models.Action ViewModelAction
		{
			get { return Contracts.Models.Action.Setup; }
		}

		#endregion
	}
}
